/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.dao.SysDictDao;
import io.renren.entity.SysDictEntity;
import io.renren.param.SysDictQueryParam;
import io.renren.service.SysDictService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("sysDictService")
public class SysDictServiceImpl extends ServiceImpl<SysDictDao, SysDictEntity> implements SysDictService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String) params.get("name");

        IPage<SysDictEntity> page = this.page(
                new Query<SysDictEntity>().getPage(params),
                new QueryWrapper<SysDictEntity>()
                        .like(StringUtils.isNotBlank(name), "name", name)
        );

        return new PageUtils(page);
    }

    public SysDictEntity queryByNameCode(SysDictQueryParam param) {
        return baseMapper.selectOne(new QueryWrapper<SysDictEntity>()
                .eq(StringUtils.isNotBlank(param.getName()),"name", param.getName())
                .eq(StringUtils.isNotBlank(param.getCode()),"code", param.getCode()));

    }

    public SysDictEntity queryByNameCodeType(SysDictQueryParam param) {
        return baseMapper.selectOne(new QueryWrapper<SysDictEntity>()
                .eq("name", param.getName())
                .eq("type", param.getType())
                .eq("code", param.getCode()));

    }

    public List<SysDictEntity> queryByNameType(SysDictQueryParam param) {
        return baseMapper.selectList(new QueryWrapper<SysDictEntity>()
                .eq("name", param.getName())
                .eq("type", param.getType()));

    }

}
